<?php

use yii\db\Migration;

/**
 * Handles the creation of table `event`.
 * Has foreign keys to the tables:
 *
 * - `department`
 * - `parentProgramm`
 * - `eventType`
 * - `eventPrice`
 */
class m210122_060453_create_event_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('event', [
            'id' => $this->primaryKey(),
            'title' => $this->string(255)->notNull(),
            'alias' => $this->string(255)->notNull(),
            'description' => $this->string(255),
            'content' => $this->text(),
            'date_start' => $this->date(),
            'date_end' => $this->date(),
            'time_start' => $this->string(45),
            'pub_date' => $this->dateTime(),
            'prev_img' => $this->string(45),
            'gallery_img' => $this->string(255),
            'id_type' => $this->integer()->notNull(),
            'id_price' => $this->integer()->notNull(),
            'request' => $this->boolean(),
        ]);

        // creates index for column `id_type`
        $this->createIndex(
            'idx-event-id_type',
            'event',
            'id_type'
        );

        // add foreign key for table `event_type`
        $this->addForeignKey(
            'fk-event-id_type',
            'event',
            'id_type',
            'event_type',
            'id',
            'RESTRICT'
        );

        // creates index for column `id_price`
        $this->createIndex(
            'idx-event-id_price',
            'event',
            'id_price'
        );

        // add foreign key for table `event_price`
        $this->addForeignKey(
            'fk-event-id_price',
            'event',
            'id_price',
            'event_price',
            'id',
            'RESTRICT'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `eventType`
        $this->dropForeignKey(
            'fk-event-id_type',
            'event'
        );

        // drops index for column `id_type`
        $this->dropIndex(
            'idx-event-id_type',
            'event'
        );

        // drops foreign key for table `eventPrice`
        $this->dropForeignKey(
            'fk-event-id_price',
            'event'
        );

        // drops index for column `id_price`
        $this->dropIndex(
            'idx-event-id_price',
            'event'
        );

        $this->dropTable('event');
    }
}